<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        th,td{
            width: 300px;
            text-align: center;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <th>id</th>
            <th>用户名</th>
            <th>密码</th>
            <th>操作</th>
        </tr>
        <% for(let item of a){ %>
            <tr>
                <td><%= item.id %></td>
                <td class="username"><%= item.username %></td>
                <td><%= item.password %></td>
                <td><button class="bt">删除</button></td>
            </tr>
            <% } %>
    </table>
</body>
</html>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
    $(".bt").on("click",function(){
        console.log($(this).parents("tr").children(".username").text());
        $.ajax({
            type:"get",
            url:"/del",
            data:{
                username:$(this).parents("tr").children(".username").text()
            },
            dataType:"json",
            success(response){
                if(response.code == 200){
                    alert(response.msg);
                    location.reload()
                }else{
                    alert(response.msg);
                }

            },
            err(){

            }
        })
    })
</script>